/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Server.lastproject;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.JTable;
import javax.swing.JTree;
import javax.swing.tree.TreePath;

/**
 *
 * @author CANG
 */
public class MyPopupMenu_NodeTable extends JPopupMenu
{
    private JMenuItem[] jmiItems;
    private ActionListener _acl;
    private JTable _jtbTableData;
    private ServerForm _server;
    private JTree _jTreeTable;
    private JTable _jtbTableStruct;
    
    public MyPopupMenu_NodeTable(JTable jtable_Data, ServerForm server, JTree jTable)
    {        
        _jtbTableData = jtable_Data;
        _server = server;
        _jTreeTable = jTable;
        
        _acl = new ActionListener()
        {
            @Override
            public void actionPerformed(ActionEvent e)
            {
                try
                {
                    TreePath tp = _jTreeTable.getSelectionPath();
                    Object ob = tp.getLastPathComponent();
                    String command = e.getActionCommand();
                    char cCommand = command.charAt(0);
                    switch(cCommand)
                    {
                        case 'C':
                        {                            
                             _server.ShowInfo(ServerForm.TABLE_CREATE, ob.toString());
                            //ShowData(String typeShow)                           
                            break;
                        }

                        case 'D':
                        {
                             _server.ShowInfo(ServerForm.TABLE_STRUCT, ob.toString());
                            break;
                        }
                            
                        case 'S':
                        {
                            _server.ShowInfo(ServerForm.TABLE_DATA, ob.toString());                            
                            String nameTable = command;
                            break;
                        }

                        case 'E':
                        {                            
                            _server.ShowInfo(ServerForm.TABLE_DATA_EDIT, ob.toString());
                            String nameTable = command;
                            break;
                        }
                        case 'd':
                        {                            
                            _server.DropTable(ob.toString());
                            String nameTable = command;
                            break;
                        }
                    }
                }
                catch(Exception ex)
                {
                    int a = 4;
                    a--;
                }                
            }            
        };
        
        jmiItems = new JMenuItem[5];
        
        jmiItems[0] = new JMenuItem("Create new Table");
        jmiItems[0].addActionListener(_acl);
        
        
        jmiItems[1] = new JMenuItem("Design");
        jmiItems[1].addActionListener(_acl);
        
        jmiItems[2] = new JMenuItem("Select top 100 Rows");
        jmiItems[2].addActionListener(_acl);
        
        jmiItems[3] = new JMenuItem("Edit top 100 Rows");
        jmiItems[3].addActionListener( _acl );
        
           jmiItems[4] = new JMenuItem("delete Table");
        jmiItems[4].addActionListener(_acl);
        
        for(int i = 0; i < jmiItems.length; i++)
        {
            add(jmiItems[i]);
        }
        
    }
    
        
    
}
